//
//  BSRecommendCategoryCell.m
//  sister
//
//  Created by 周冰烽 on 2017/2/14.
//  Copyright © 2017年 周冰烽. All rights reserved.
//

#import "BSRecommendCategoryCell.h"

@implementation BSRecommendCategoryCell
-(UIView *)leftView{
    if (_leftView == nil) {
        _leftView = [[UIView alloc]init];
        _leftView.backgroundColor = [UIColor redColor];
        _leftView.translatesAutoresizingMaskIntoConstraints = NO;
        [self addSubview:_leftView];
        NSDictionary *dictView = NSDictionaryOfVariableBindings(_leftView);
        [self addConstraints:[NSLayoutConstraint
                              constraintsWithVisualFormat:@"H:|-0-[_leftView(10)]"
                              options:0
                              metrics:nil
                              views:dictView]];
        [self addConstraints:[NSLayoutConstraint
                              constraintsWithVisualFormat:@"V:|-0-[_leftView]-0-|"
                              options:0
                              metrics:nil
                              views:dictView]];
    }
    return _leftView;
}

-(void)layoutSubviews{
    [super layoutSubviews];
    self.textLabel.x = 20;
    self.textLabel.y = 2;
    self.textLabel.height = self.contentView.height - 2*self.textLabel.y;
    self.selectionStyle = UITableViewCellSelectionStyleNone;
    [self setupUI];
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    self.textLabel.textColor = selected ? [UIColor redColor] : [UIColor BS_Red:78 Green:78 Blue:78 Alpha:1.0];
    self.textLabel.backgroundColor = selected ? [UIColor whiteColor] : BSGlobalColor;
    self.backgroundColor = selected ? [UIColor whiteColor] :BSGlobalColor;
    self.leftView.hidden = !selected;
}

-(void)setupUI{
    UIView *bottomView = [[UIView alloc]init];
    bottomView.backgroundColor = [UIColor whiteColor];
    bottomView.translatesAutoresizingMaskIntoConstraints = NO;
    [self addSubview:bottomView];
    
    NSDictionary *dictView = NSDictionaryOfVariableBindings(bottomView);
    [self addConstraints:[NSLayoutConstraint
                         constraintsWithVisualFormat:@"H:|-0-[bottomView]-0-|"
                         options:0
                         metrics:nil
                          views:dictView]];
    [self addConstraints:[NSLayoutConstraint
                          constraintsWithVisualFormat:@"V:[bottomView(0.5)]-0-|"
                          options:0
                          metrics:nil
                          views:dictView]];
    
}

@end
